<template>
  <div>
    <ul class="list-box">
      <li class="theader">
        <span>时间</span>
        <span>关联企业</span>
        <!-- <span>科研产出</span> -->
        <span>科研成果</span>
      </li>
      <li v-for="(item, index) in listData" :key="index" class="tbody" :class="{active: active===index}" @click="highlight(item, index)">
        <span>{{item.startYear}}</span>
        <span>{{item.an}}</span>
        <span>{{item.title}}</span>
        <!-- <span>{{item.result.join(';')}}</span> -->
      </li>
      <li v-if="listData.length<0" class="no-data">{{noData}}</li>
    </ul>
    <el-pagination
      background
      layout="prev, pager, next"
      :total="total"
      :page-size="ips"
      :current-page.sync="ipi"
      @current-change="getCurrentPage"
      class="elpagination">
    </el-pagination>
  </div>
</template>

<script>
import { mapState } from "vuex";
export default {
  props: {
    record: {
      type: Array
    }
  },
  data() {
    return {
      active: -1,
      listData: [],
      listAllData: [],
      total: 0,
      ipi: 1, // 页码
      ips: 6, // 每页展示条数
      patentHeaderStyle: function(){
        return 'font-weight: 600; color: #241c75;'
      },
      patentCellStyle: function() {
        return 'color: #7674a3'
      },
      noData: '数据加载中...'
    }
  },
  computed: {
    ...mapState(['companyNameAndEid'])
  },
  methods: {
    getData() {
      let record = JSON.parse(JSON.stringify(this.record))
      record.forEach(v => {
        v.startYear = v.start.split('-')[0]
      })
      let newRecord = []
      record.forEach(v => {
        if (v.city !== '') {
          v.startYear = v.start.split('-')[0]
          newRecord.push(v)
        }
      })
      this.listAllData = newRecord
      this.listData = newRecord.slice(0, this.ipi * this.ips)
      this.total = newRecord.length

      this.active = 0
      this.$Bus.$emit('curWorkExperience', {
        item: this.listData[0],
        active: this.active
      })
    },
    getCurrentPage(val) {
      this.ipi = val
      this.active = -1
      this.listData = this.listAllData.slice((this.ipi - 1) * this.ips, this.ipi * this.ips)
    },
    // 高亮选中，左侧图表联动
    highlight(item, index) {
      if (this.active !== index) {
        this.active = index
      } else {
        this.active = -1
      }
      this.$Bus.$emit('curWorkExperience', {
        item,
        active: this.active
      })
    }
  },
  watch: {
    record() {
      if (this.record.length > 0) {
        this.getData()
      }
    }
  },
  mounted() {
    if (this.record.length > 0) {
      this.getData()
    }
  },
  beforeDestroy() {
    this.$Bus.$off('curWorkExperience')
  }
}
</script>

<style lang="scss" scoped>
.list-box {
  position: relative;
  padding: 0 21px;
  li {
    position: relative;
    display: flex;
    padding: 0 22px;
    list-style: none;
    color: #7674a3;
    cursor: pointer;
    &.active {
      box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
      color: $mainColor;
    }
    span {
      &:nth-child(1) {
        flex: 0.5;
        margin-left: 10px;
      }
      flex: 1;
      padding-left: 4px;
      padding-right: 4px;
      font-size: 14px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }
  .theader {
    line-height: 44px;
    border-bottom: 1px solid #f0f0fb;
    span {
      &:nth-child(1) {
        flex: 0.5;
        margin-left: 10px;
      }
      font-weight: bold;
      color: #2d3a86;
    }
  }
  .tbody {
    line-height: 18px;
    padding-top: 13px;
    padding-bottom: 13px;
    &:hover {
      box-shadow: 0 2px 12px 0 rgba(0,0,0,.1);
      color: $mainColor;
      cursor: pointer;
    }
  }
}
.result {
  position: relative;
}
.elpagination {
  padding: 0 21px;
  margin: 27px 0;
  text-align: right;
}
</style>